package ui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class Begin extends JFrame implements ActionListener {
	private JButton uesrenrollButton;
	private JButton userLoginButton;

	public Begin() {
		JFrame jFrame = new JFrame("用户登录/注册界面");
		jFrame.setLayout(new BorderLayout());
		JPanel jp1 = new JPanel(new GridLayout(1, 2, 10, 10));//设置新面板
		jp1.setBorder(BorderFactory.createTitledBorder("用户登录/注册"));
		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

		setTitle("用户登录/注册界面");
		setSize(300, 150);
		setLocationRelativeTo(null);
		

		// 监听右上角的退出按钮
		this.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent windowEvent) {
				System.exit(0);
			}
		});
		uesrenrollButton = new JButton("用户注册");
		userLoginButton = new JButton("用户登录");
		
		jp1.add(userLoginButton);
		jp1.add(uesrenrollButton);
		JPanel jp2 = new JPanel();
		add(jp2, BorderLayout.SOUTH);// 把按钮放到窗口最下方
		getContentPane().add(jp1,BorderLayout.CENTER);

		uesrenrollButton.addActionListener(this);
		userLoginButton.addActionListener(this);

		this.setVisible(true);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == uesrenrollButton) {
			this.dispose();
			new Enroll();
		} else if (e.getSource() == userLoginButton) {
			this.dispose();
			new Bind();
		}
	}
}


